package com.singfan.app.controller;

import com.singfan.app.controller.model.HttpModelConverter;
import com.singfan.app.controller.model.ResponseModelBase;
import com.singfan.app.controller.model.request.*;
import com.singfan.app.controller.model.response.*;
import com.singfan.app.controller.model.response.partial.*;
import com.singfan.app.util.AppointmentUtil;
import com.singfan.app.util.RequestParamChecker;
import com.singfan.common.util.EncryptionUtil;
import com.singfan.common.util.JsonUtil;
import com.singfan.common.util.StringUtil;
import com.singfan.core.component.BarberTokenHolder;
import com.singfan.core.component.CustomerTokenHolder;
import com.singfan.core.component.ShopTokenHolder;
import com.singfan.core.dao.database.config.ConfigDataManager;
import com.singfan.core.dao.database.model.*;
import com.singfan.core.dao.database.model.constant.BusinessStatusType;
import com.singfan.core.dao.database.model.constant.HairServiceType;
import com.singfan.core.dao.database.model.constant.OrderStatusType;
import com.singfan.core.dao.database.model.temp.OrderContent;
import com.singfan.core.dao.database.model.temp.OrderItem;
import com.singfan.core.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * 门店端的API接口
 * Author: hansonghe
 * Date: 2015-10-08 14:30
 * Desc:
 */
@Controller
public class ShopClientController extends SingFanControllerBase {
    @Autowired
    private IOrderService orderService;

    @RequestMapping(value="/v1/store/login", method= RequestMethod.POST)
    public void login(HttpServletRequest request, HttpServletResponse response) {
        StoreLoginResponse result = new StoreLoginResponse();
        StoreLoginRequest storeLoginRequest = request2Bean(request, StoreLoginRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeLoginRequest.getAccessToken();

        String phoneNumber = storeLoginRequest.getPhoneNum();
        String pwd = storeLoginRequest.getPwd();

        boolean checkResult = true;
        if (StringUtil.isNullOrEmpty(phoneNumber)){
            checkResult = false;
        }
        else if (StringUtil.isNullOrEmpty(pwd)){
            checkResult = false;
        }

        if (checkResult){
            Shop shop = shopService.findShop(phoneNumber);
            if (shop != null){
                if (shop.getStatus() != BusinessStatusType.FORBIDDEN){
                    String password = EncryptionUtil.md5(pwd + "-" + shop.getPasswordSalt());
                    if (password.equals(shop.getPassword())){
                        String token = shopService.createAccessToken(shop.getId(), shop.getCityId(), shop.getStatus());
                        result.setResultCode(ResultCode.SUCCESS);
                        result.setAccessToken(token);
                        result.setShopMasterName(shop.getMasterShopName());
                        result.setShopSlaveName(shop.getSlaveShopName());
                        ShopHair shopHair = shopService.findShopHair(shop.getId());
                        result.setShopLevel(shopHair.getHonor());
                        traceLog.debug(String.format("ShopClientController.login() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, phoneNumber:%4$s, pwd:%5$s", ResultCode.SUCCESS, ip, accessToken, phoneNumber, pwd));
                    }
                    else {
                        result.setResultCode(ResultCode.SHOP_PWD_ERROR);
                        traceLog.error(String.format("ShopClientController.login() error with SHOP_PWD_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, phoneNumber:%4$s, pwd:%5$s", ResultCode.SHOP_PWD_ERROR, ip, accessToken, phoneNumber, pwd));
                    }
                }
                else{
                    result.setResultCode(ResultCode.ACCOUNT_DISABLED);
                    traceLog.error(String.format("ShopClientController.login() error with ACCOUNT_DISABLED -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, phoneNumber:%4$s, pwd:%5$s", ResultCode.ACCOUNT_DISABLED, ip, accessToken, phoneNumber, pwd));
                }
            }
            else {
                result.setResultCode(ResultCode.SHOP_NOT_EXIST);
                traceLog.error(String.format("ShopClientController.login() error with SHOP_NOT_EXIST -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, phoneNumber:%4$s, pwd:%5$s", ResultCode.SHOP_NOT_EXIST, ip, accessToken, phoneNumber, pwd));
            }
        }
        else {
            result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
            traceLog.error(String.format("ShopClientController.login() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, phoneNumber:%4$s, pwd:%5$s", ResultCode.REQUEST_PARAM_ERROR, ip, accessToken, phoneNumber, pwd));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/changepwd", method= RequestMethod.POST)
    public void changePwd(HttpServletRequest request, HttpServletResponse response) {
        StoreChangePwdResponse result = new StoreChangePwdResponse();
        StoreChangePwdRequest storeChangePwdRequest = request2Bean(request, StoreChangePwdRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeChangePwdRequest.getAccessToken();

        String oldPwd = storeChangePwdRequest.getOldpwd();
        String pwd = storeChangePwdRequest.getPwd();

        long shopId = getShopId();
        if (shopId > 0){
            boolean checkResult = true;
            if (StringUtil.isNullOrEmpty(oldPwd)){
                checkResult = false;
            }
            else if (StringUtil.isNullOrEmpty(pwd)){
                checkResult = false;
            }

            if (checkResult){
                Shop shop = shopService.findShop(shopId);

                String password = EncryptionUtil.md5(oldPwd + "-" + shop.getPasswordSalt());
                if (password.equals(shop.getPassword())){
                    shopService.changePwd(shopId, pwd);
                    traceLog.debug(String.format("ShopClientController.changePwd() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, oldPwd:%4$s, pwd:%5$s", ResultCode.SUCCESS, ip, accessToken, oldPwd, pwd));
                }
                else {
                    result.setResultCode(ResultCode.SHOP_PWD_ERROR);
                    traceLog.error(String.format("ShopClientController.changePwd() error with SHOP_PWD_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, oldPwd:%4$s, pwd:%5$s", ResultCode.SHOP_PWD_ERROR, ip, accessToken, oldPwd, pwd));
                }
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.changePwd() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, oldPwd:%4$s, pwd:%5$s", ResultCode.REQUEST_PARAM_ERROR, ip, accessToken, oldPwd, pwd));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.changePwd() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, oldPwd:%4$s, pwd:%5$s", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, oldPwd, pwd));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/home", method= RequestMethod.POST)
    public void home(HttpServletRequest request, HttpServletResponse response) {
        StoreHomeResponse result = new StoreHomeResponse();
        StoreHomeRequest storeHomeRequest = request2Bean(request, StoreHomeRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeHomeRequest.getAccessToken();

        long shopId = getShopId();
        if (shopId > 0){
            int todayIncome = orderService.findShopOneDayIncome(shopId, AppointmentUtil.getTodayTime());
            int todayOrderCount = orderService.findShopOneDayOrderCount(shopId, AppointmentUtil.getTodayTime());
            result.setResultCode(ResultCode.SUCCESS);
            result.setOrderIncome(todayIncome);
            result.setOrderCount(todayOrderCount);

            traceLog.debug(String.format("ShopClientController.home() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s", ResultCode.SUCCESS, ip, accessToken));
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.home() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/detail", method= RequestMethod.POST)
    public void detail(HttpServletRequest request, HttpServletResponse response) {
        StoreDetailResponse result = new StoreDetailResponse();
        StoreDetailRequest storeDetailRequest = request2Bean(request, StoreDetailRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeDetailRequest.getAccessToken();

        long shopId = getShopId();
        if (shopId > 0){
            Shop shop = shopService.findShop(shopId);

            result.setResultCode(ResultCode.SUCCESS);
            result.setShopImgUrl(shop.getShopIconUrl());
            List<String> imgUrlList = StringUtil.split(shop.getImgList(), ";");
            result.setShopImgUrlList(imgUrlList);
            result.setShopMasterName(shop.getMasterShopName());
            result.setShopSlaveName(shop.getSlaveShopName());
            result.setShopDesc(shop.getDescription());
            LocationPartial locationPartial = new LocationPartial();
            locationPartial.setShopMasterName(shop.getMasterShopName());
            locationPartial.setShopSlaveName(shop.getSlaveShopName());
            locationPartial.setAddressText(shop.getAddress());
            locationPartial.setLatitude(String.valueOf(shop.getLatitude().doubleValue()));
            locationPartial.setLongitude(String.valueOf(shop.getLongitude().doubleValue()));
            result.setShopLocation(locationPartial);
            result.setShopTelNum(shop.getContactNumber());
            result.setBusinessCircleName(ConfigDataManager.getInstance().getBusinessCircleConfigMap(shop.getBusinessCircleId()).getName());

            traceLog.debug(String.format("ShopClientController.detail() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s", ResultCode.SUCCESS, ip, accessToken));
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.detail() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/historyincome", method= RequestMethod.POST)
    public void historyIncome(HttpServletRequest request, HttpServletResponse response) {
        StoreHistoryIncomeResponse result = new StoreHistoryIncomeResponse();
        StoreHistoryIncomeRequest storeHistoryIncomeRequest = request2Bean(request, StoreHistoryIncomeRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeHistoryIncomeRequest.getAccessToken();
        int dateTime = storeHistoryIncomeRequest.getDateTime();

        long shopId = getShopId();
        if (shopId > 0){
            if (RequestParamChecker.checkAppointmentDayTime(dateTime)){
                int shopIncome = 0;
                int serviceIncome = 0;
                List<BarberIncomePartial> barberIncomePartialList = new ArrayList<>();
                List<ServiceIncomePartial> serviceIncomePartialList = new ArrayList<>();
                List<Orders> ordersList = orderService.findShopOneDayOrderList(shopId, dateTime);
                Map<Long, BarberIncomePartial> barberIncomeMap = new HashMap<>();
                Map<Integer, ServiceIncomePartial> serviceIncomeMap = new HashMap<>();
                if (ordersList.size() > 0){
                    for (Orders order : ordersList){
                        //技师收入
                        long barberId = order.getBarberId();
                        if (!barberIncomeMap.containsKey(barberId)){
                            barberIncomeMap.put(barberId, new BarberIncomePartial());
                        }
                        BarberIncomePartial barberIncomePartial = barberIncomeMap.get(barberId);
                        barberIncomePartial.setOrderCount(barberIncomePartial.getOrderCount() + 1);
                        barberIncomePartial.setBarberIncome(barberIncomePartial.getBarberIncome() + order.getOriginalPrice());

                        //服务收入
                        if (order.getOrderType() == 2){
                            OrderContent orderContent = JsonUtil.json2Bean(order.getServiceContext(), OrderContent.class);
                            List<OrderItem> orderItemList = orderContent.getOrderItemList();
                            for (OrderItem orderItem : orderItemList){
                                int serviceType = orderItem.getServiceType();
                                if (!serviceIncomeMap.containsKey(serviceType)){
                                    ServiceIncomePartial serviceIncomePartial = new ServiceIncomePartial();
                                    serviceIncomePartial.setServiceType(serviceType);
                                    serviceIncomeMap.put(serviceType, serviceIncomePartial);
                                }

                                ServiceIncomePartial serviceIncomePartial = serviceIncomeMap.get(serviceType);
                                serviceIncomePartial.setOrderCount(serviceIncomePartial.getOrderCount() + 1);
                                serviceIncomePartial.setServiceIncome(serviceIncomePartial.getServiceIncome() + orderItem.getPrice());
                            }
                        }
                    }

                    List<Barber> barberList = barberService.selectBarberListByShopId(shopId, -1, -1, -1);
                    for (Barber barber : barberList){
                        BarberIncomePartial barberIncomePartial = barberIncomeMap.get(barber.getId());
                        if (barberIncomePartial != null){
                            barberIncomePartial.setAvatorImageUrl(barber.getAvatar());
                            barberIncomePartial.setRealName(barber.getRealName());
                            barberIncomePartial.setPosition(ConfigDataManager.getInstance().getBarberPositionConfig(barber.getPositionId()).getPosition());
                        }
                    }

                    Collection<BarberIncomePartial> barberIncomePartialCollection = barberIncomeMap.values();
                    for (BarberIncomePartial barberIncomePartial : barberIncomePartialCollection){
                        barberIncomePartialList.add(barberIncomePartial);
                    }

                    Collection<ServiceIncomePartial> serviceIncomePartialCollection = serviceIncomeMap.values();
                    for (ServiceIncomePartial serviceIncomePartial : serviceIncomePartialCollection){
                        serviceIncomePartialList.add(serviceIncomePartial);
                    }
                }

                result.setResultCode(ResultCode.SUCCESS);
                result.setShopIncome(shopIncome);
                result.setServiceIncome(serviceIncome);
                result.setBarberIncomePartialList(barberIncomePartialList);
                result.setServiceIncomePartialList(serviceIncomePartialList);

                traceLog.debug(String.format("ShopClientController.historyIncome() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, dateTime:%4$d", ResultCode.SUCCESS, ip, accessToken, dateTime));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.historyIncome() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, dateTime:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, dateTime));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.historyIncome() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, dateTime:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, dateTime));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/monthincome", method= RequestMethod.POST)
    public void monthIncome(HttpServletRequest request, HttpServletResponse response) {
        StoreMonthIncomeResponse result = new StoreMonthIncomeResponse();
        StoreMonthIncomeRequest storeMonthIncomeRequest = request2Bean(request, StoreMonthIncomeRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeMonthIncomeRequest.getAccessToken();
        int monthTime = storeMonthIncomeRequest.getMonthTime();

        long shopId = getShopId();
        if (shopId > 0){
            if (RequestParamChecker.checkAppointmentMonthTime(monthTime)){
                int monthIncome = orderService.findShopOneMonthIncome(shopId, AppointmentUtil.getTodayTime());
                int monthOrderCount = orderService.findShopOneMonthOrderCount(shopId, AppointmentUtil.getTodayTime());
                result.setResultCode(ResultCode.SUCCESS);
                result.setIncome(monthIncome);
                result.setOrderCount(monthOrderCount);

                traceLog.debug(String.format("ShopClientController.monthIncome() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, monthTime:%4$d", ResultCode.SUCCESS, ip, accessToken, monthTime));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.monthIncome() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, monthTime:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, monthTime));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.monthIncome() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, monthTime:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, monthTime));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/checkcode", method= RequestMethod.POST)
    public void checkCode(HttpServletRequest request, HttpServletResponse response) {
        StoreCheckCodeResponse result = new StoreCheckCodeResponse();
        StoreCheckCodeRequest storeCheckCodeRequest = request2Bean(request, StoreCheckCodeRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeCheckCodeRequest.getAccessToken();
        String code = storeCheckCodeRequest.getCode();

        long shopId = getShopId();
        if (shopId > 0){
            if (!StringUtil.isNullOrEmpty(code)){
                Orders order = orderService.findOrdersBySecurityCode(shopId, code);
                if (order != null){
                    result.setCheckResult(true);
                    result.setOrderImgUrl(order.getOrderIcon());
                    result.setOrderName(order.getOrderName());
                    Barber barber = barberService.findBarber(order.getBarberId());
                    BarberPartial barberPartial = HttpModelConverter.barber2BarberPartial(barber);
                    result.setBarberPartial(barberPartial);
                    result.setCustomerPhoneNum(order.getCustomerPhoneNumber());
                    result.setOriginalPrice(order.getOriginalPrice());
                    result.setOrderPrice(order.getPrice());
                    result.setOrderStatus(order.getStatus());
                    result.setOrderCreateTime(order.getCreateTime().getTime());
                    result.setOrderAppointmentDay(String.valueOf(order.getAppointmentDay()));
                    result.setOrderAppointmentClock(order.getAppointmentClock());
                    result.setOrderID(order.getId());
                }
                else {
                    result.setCheckResult(false);
                }

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.checkCode() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, code:%4$s", ResultCode.SUCCESS, ip, accessToken, code));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.checkCode() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, code:%4$s", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, code));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.checkCode() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, code:%4$s", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, code));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/startservice", method= RequestMethod.POST)
    public void startService(HttpServletRequest request, HttpServletResponse response) {
        StoreStartServiceResponse result = new StoreStartServiceResponse();
        StoreStartServiceRequest storeStartServiceRequest = request2Bean(request, StoreStartServiceRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeStartServiceRequest.getAccessToken();
        long orderID = storeStartServiceRequest.getOrderID();

        long shopId = getShopId();
        if (shopId > 0){
            Orders order = orderService.findOrdersById(orderID);
            if (order != null && order.getShopId() == shopId && order.getStatus() == OrderStatusType.PAID){
                orderService.updateOrderStatus(orderID, OrderStatusType.SERVICE_START);

                result.setResultCode(ResultCode.SUCCESS);
                traceLog.debug(String.format("ShopClientController.startService() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderId:%4$d", ResultCode.SUCCESS, ip, accessToken, orderID));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.startService() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, orderID));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.startService() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, orderID));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/list", method= RequestMethod.POST)
    public void barberList(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberListResponse result = new StoreBarberListResponse();
        StoreBarberListRequest storeBarberListRequest = request2Bean(request, StoreBarberListRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberListRequest.getAccessToken();
        int listType = storeBarberListRequest.getListType();

        long shopId = getShopId();
        if (shopId > 0){
            if (BusinessStatusType.isBusinessStatusType(listType)){
                List<Barber> barberList = barberService.findShopBarberList(shopId, listType);
                List<BarberPartial> barberPartialList = new ArrayList<>();
                for (Barber barber : barberList){
                    BarberPartial barberPartial = HttpModelConverter.barber2BarberPartial(barber);
                    barberPartialList.add(barberPartial);
                }
                result.setResultCode(ResultCode.SUCCESS);
                result.setBarberPartialList(barberPartialList);
                traceLog.debug(String.format("ShopClientController.barberList() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, listType:%4$d", ResultCode.SUCCESS, ip, accessToken, listType));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberList() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, listType:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, listType));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberList() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, listType:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, listType));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/review", method= RequestMethod.POST)
    public void barberReview(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberReviewResponse result = new StoreBarberReviewResponse();
        StoreBarberReviewRequest storeBarberReviewRequest = request2Bean(request, StoreBarberReviewRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberReviewRequest.getAccessToken();
        long barberId = storeBarberReviewRequest.getBarberId();
        boolean reviewType = storeBarberReviewRequest.isReviewType();

        long shopId = getShopId();
        if (shopId > 0){
            Barber barber = barberService.findBarber(barberId);
            if (barber != null && barber.getShopId() == shopId && (barber.getStatus() == BusinessStatusType.NOT_VERIFY || barber.getStatus() == BusinessStatusType.VERIFY_NOT_PASS)){
                int status;
                if (reviewType){
                    status = BusinessStatusType.VERIFY_PASSED;
                }
                else{
                    status = BusinessStatusType.VERIFY_NOT_PASS;
                }
                barberService.updateBarberStatus(barberId, status);
                result.setResultCode(ResultCode.SUCCESS);
                traceLog.debug(String.format("ShopClientController.barberReview() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, reviewType:%4$b", ResultCode.SUCCESS, ip, accessToken, reviewType));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberReview() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, reviewType:%4$b", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, reviewType));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberReview() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, reviewType:%4$b", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, reviewType));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/delete", method= RequestMethod.POST)
    public void barberDelete(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberDeleteResponse result = new StoreBarberDeleteResponse();
        StoreBarberDeleteRequest storeBarberDeleteRequest = request2Bean(request, StoreBarberDeleteRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberDeleteRequest.getAccessToken();
        long barberId = storeBarberDeleteRequest.getBarberId();

        long shopId = getShopId();
        if (shopId > 0){
            Barber barber = barberService.findBarber(barberId);
            if (barber != null && barber.getShopId() == shopId){
                barber.setShopId(0);
                barber.setStatus(BusinessStatusType.NOT_VERIFY);
                barber.setMasterShopName(null);
                barber.setSlaveShopName(null);
                barber.setAddress("");
                barber.setLongitude(BigDecimal.ZERO);
                barber.setLatitude(BigDecimal.ZERO);

                barberService.updateBarberDetail(barber);
                barberService.updateBarberHairstyleStatus(barber.getId(), BusinessStatusType.NOT_VERIFY);

                result.setResultCode(ResultCode.SUCCESS);
                traceLog.debug(String.format("ShopClientController.barberDelete() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.SUCCESS, ip, accessToken, barberId));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberDelete() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberDelete() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/comment/list", method= RequestMethod.POST)
    public void barberCommentList(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberCommentListResponse result = new StoreBarberCommentListResponse();
        StoreBarberCommentListRequest storeBarberCommentListRequest = request2Bean(request, StoreBarberCommentListRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberCommentListRequest.getAccessToken();
        long barberId = storeBarberCommentListRequest.getBarberId();
        int pageIndex = storeBarberCommentListRequest.getPageIndex();
        int pageSize = storeBarberCommentListRequest.getPageSize();

        long shopId = getShopId();
        if (shopId > 0){
            if (RequestParamChecker.checkPageIndexAndSize(pageIndex, pageSize)){
                result.setResultCode(ResultCode.SUCCESS);
                if (pageIndex == 0){
                    result.setNewList(true);
                }
                else {
                    result.setNewList(false);
                }
                List<BarberComment> barberCommentList = barberService.findBarberCommentList(barberId, pageIndex, pageSize);
                List<OrderCommentPartial> orderCommentPartialList = new ArrayList<>(barberCommentList.size());
                for (BarberComment barberComment : barberCommentList){
                    OrderCommentPartial orderCommentPartial = new OrderCommentPartial();
                    orderCommentPartial.setCustomName(barberComment.getCustomerName());
                    orderCommentPartial.setCustomAvatar(barberComment.getCustomerAvatar());
                    orderCommentPartial.setCommentContent(barberComment.getCommentText());
                    orderCommentPartial.setCommentImgUrlList(StringUtil.split(barberComment.getCommentImgList(), ";"));
                    orderCommentPartial.setCommentLevel(barberComment.getCommentStar());
                    orderCommentPartial.setCommentTime(barberComment.getCreateTime().getTime());

                    orderCommentPartialList.add(orderCommentPartial);
                }
                result.setOrderCommentPartialList(orderCommentPartialList);

                traceLog.debug(String.format("ShopClientController.barberCommentList() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, pageIndex:%5$d, pageSize:%6$d", ResultCode.SUCCESS, ip, accessToken, barberId, pageIndex, pageSize));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberCommentList() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, pageIndex:%5$d, pageSize:%6$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId, pageIndex, pageSize));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberCommentList() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, pageIndex:%5$d, pageSize:%6$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId, pageIndex, pageSize));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/detail", method= RequestMethod.POST)
    public void barberDetail(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberDetailResponse result = new StoreBarberDetailResponse();
        StoreBarberDetailRequest storeBarberDetailRequest = request2Bean(request, StoreBarberDetailRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberDetailRequest.getAccessToken();
        long barberId = storeBarberDetailRequest.getBarberId();

        long shopId = getShopId();
        if (shopId > 0){
            Barber barber = barberService.findBarber(barberId);
            if (barber!=null && barber.getShopId() == shopId){
                result.setResultCode(ResultCode.SUCCESS);
                result.setAvatar(barber.getAvatar());
                result.setNickName(barber.getNickName());
                result.setGender(barber.getGender());
                result.setRealName(barber.getRealName());
                result.setIdCardNum(barber.getIdCardNumber());
                result.setPhoneNum(barber.getPhoneNumber());
                if (barber.getPositionId() > 0){
                    result.setPosition(ConfigDataManager.getInstance().getBarberPositionConfig(barber.getPositionId()).getPosition());
                }
                else {
                    result.setPosition("");
                }
                result.setCutHairOriginalPrice(barber.getHairCutOriginalPrice());
                result.setCutHairPrice(barber.getHairCutRealPrice());
                result.setModellingOriginalPrice(barber.getHairModelingOriginalPrice());
                result.setModellingPrice(barber.getHairModelingRealPrice());
                traceLog.debug(String.format("ShopClientController.barberDetail() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.SUCCESS, ip, accessToken, barberId));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberDetail() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberDetail() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/barber/detail/update", method= RequestMethod.POST)
    public void barberUpdate(HttpServletRequest request, HttpServletResponse response) {
        StoreBarberDetailUpdateResponse result = new StoreBarberDetailUpdateResponse();
        StoreBarberDetailUpdateRequest storeBarberDetailUpdateRequest = request2Bean(request, StoreBarberDetailUpdateRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeBarberDetailUpdateRequest.getAccessToken();
        long barberId = storeBarberDetailUpdateRequest.getBarberId();
        int cutHairOriginalPrice = storeBarberDetailUpdateRequest.getCutHairOriginalPrice();
        int cutHairPrice = storeBarberDetailUpdateRequest.getCutHairPrice();
        int modellingOriginalPrice = storeBarberDetailUpdateRequest.getModellingOriginalPrice();
        int modellingPrice = storeBarberDetailUpdateRequest.getModellingPrice();

        long shopId = getShopId();
        if (shopId > 0){
            Barber barber = barberService.findBarber(barberId);
            if (barber !=null && barber.getShopId() == shopId
                    && (cutHairOriginalPrice >= cutHairPrice && cutHairPrice >= 0)
                    && (modellingOriginalPrice >= modellingPrice && modellingPrice >= 0)){

                barber.setHairCut(cutHairPrice == 0);
                barber.setHairCutOriginalPrice(cutHairOriginalPrice);
                barber.setHairCutRealPrice(cutHairPrice);
                barber.setHairModeling(modellingPrice == 0);
                barber.setHairModelingOriginalPrice(modellingOriginalPrice);
                barber.setHairModelingRealPrice(modellingPrice);
                barberService.updateBarberDetail(barber);

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.barberUpdate() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, cutHairOriginalPrice:%5$d, cutHairPrice:%6$d, modellingOriginalPrice:%7$d, modellingPrice:%8$d", ResultCode.SUCCESS, ip, accessToken, barberId, cutHairOriginalPrice, cutHairPrice, modellingOriginalPrice, modellingPrice));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.barberUpdate() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, cutHairOriginalPrice:%5$d, cutHairPrice:%6$d, modellingOriginalPrice:%7$d, modellingPrice:%8$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId, cutHairOriginalPrice, cutHairPrice, modellingOriginalPrice, modellingPrice));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.barberUpdate() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, barberId:%4$d, cutHairOriginalPrice:%5$d, cutHairPrice:%6$d, modellingOriginalPrice:%7$d, modellingPrice:%8$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, barberId, cutHairOriginalPrice, cutHairPrice, modellingOriginalPrice, modellingPrice));
        }

        bean2Response(response, result);
    }


    @RequestMapping(value="/v1/store/price/list", method= RequestMethod.POST)
    public void priceList(HttpServletRequest request, HttpServletResponse response) {
        StorePriceListResponse result = new StorePriceListResponse();
        StorePriceListRequest storePriceListRequest = request2Bean(request, StorePriceListRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storePriceListRequest.getAccessToken();
        int serviceType = storePriceListRequest.getServiceType();

        long shopId = getShopId();
        if (shopId > 0){
            if (serviceType == HairServiceType.HAIR_PERM
                    || serviceType == HairServiceType.HAIR_DYE
                    || serviceType == HairServiceType.HAIR_NURSE){

                List<ShopHairService> shopHairServiceList = shopService.selectShopHairServiceList(shopId);
                List<PriceMenuItemPartial> priceMenuItemPartialList = new ArrayList<>(shopHairServiceList.size());
                for (ShopHairService shopHairService : shopHairServiceList){
                    if (shopHairService.getServiceType() == serviceType){
                        PriceMenuItemPartial itemPartial = new PriceMenuItemPartial();

                        itemPartial.setItemType(shopHairService.getServiceType());
                        itemPartial.setItemID(shopHairService.getId());
                        itemPartial.setItemName(shopHairService.getServiceName());
                        itemPartial.setOriginalPrice(shopHairService.getOriginalPrice());
                        itemPartial.setCurrentPrice(shopHairService.getRealPrice());

                        priceMenuItemPartialList.add(itemPartial);
                    }
                }
                result.setPriceMenuItemList(priceMenuItemPartialList);

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.priceList() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d", ResultCode.SUCCESS, ip, accessToken, serviceType));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.priceList() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, serviceType));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.priceList() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, serviceType));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/price/add", method= RequestMethod.POST)
    public void priceAdd(HttpServletRequest request, HttpServletResponse response) {
        StorePriceAddResponse result = new StorePriceAddResponse();
        StorePriceAddRequest storePriceAddRequest = request2Bean(request, StorePriceAddRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storePriceAddRequest.getAccessToken();
        int serviceType = storePriceAddRequest.getServiceType();
        String serviceName = storePriceAddRequest.getItemName();
        int originalPrice = storePriceAddRequest.getOriginalPrice();
        int singfanPrice = storePriceAddRequest.getSingfanPrice();

        long shopId = getShopId();
        if (shopId > 0){
            boolean checkResult = true;
            if (!(serviceType == HairServiceType.HAIR_PERM
                    || serviceType == HairServiceType.HAIR_DYE
                    || serviceType == HairServiceType.HAIR_NURSE)){
                checkResult = false;
            }
            else if (StringUtil.isNullOrEmpty(serviceName)){
                checkResult = false;
            }
            else if (originalPrice < singfanPrice){
                checkResult = false;
            }
            else if(singfanPrice < 0){
                checkResult = false;
            }

            if (checkResult){
                ShopHairService shopHairService = new ShopHairService();
                shopHairService.setShopId(shopId);
                shopHairService.setServiceType(serviceType);
                shopHairService.setServiceName(serviceName);
                shopHairService.setOriginalPrice(originalPrice);
                shopHairService.setRealPrice(singfanPrice);
                shopHairService.setCreateTime(new Date());

                shopService.addHairService(shopHairService);

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.priceAdd() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.SUCCESS, ip, accessToken, serviceType, serviceName, originalPrice, singfanPrice));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.priceAdd() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, serviceType, serviceName, originalPrice, singfanPrice));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.priceAdd() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, serviceType:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, serviceType, serviceName, originalPrice, singfanPrice));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/price/update", method= RequestMethod.POST)
    public void priceUpdate(HttpServletRequest request, HttpServletResponse response) {
        StorePriceUpdateResponse result = new StorePriceUpdateResponse();
        StorePriceUpdateRequest storePriceUpdateRequest = request2Bean(request, StorePriceUpdateRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storePriceUpdateRequest.getAccessToken();
        int itemId = storePriceUpdateRequest.getItemId();
        String serviceName = storePriceUpdateRequest.getItemName();
        int originalPrice = storePriceUpdateRequest.getOriginalPrice();
        int singfanPrice = storePriceUpdateRequest.getSingfanPrice();

        long shopId = getShopId();
        if (shopId > 0){
            boolean checkResult = true;
            if (itemId <= 0){
                checkResult = false;
            }
            else if (StringUtil.isNullOrEmpty(serviceName)){
                checkResult = false;
            }
            else if (originalPrice < singfanPrice){
                checkResult = false;
            }
            else if(singfanPrice < 0){
                checkResult = false;
            }

            ShopHairService shopHairService = shopService.findShopHairService(itemId);
            if (shopHairService == null || shopHairService.getShopId() != shopId){
                checkResult = false;
            }

            if (checkResult){
                shopHairService.setServiceName(serviceName);
                shopHairService.setOriginalPrice(originalPrice);
                shopHairService.setRealPrice(singfanPrice);

                shopService.updateShopHairService(shopHairService);

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.priceUpdate() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.SUCCESS, ip, accessToken, itemId, serviceName, originalPrice, singfanPrice));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.priceUpdate() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, itemId, serviceName, originalPrice, singfanPrice));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.priceUpdate() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d, serviceName:%5$s, originalPrice:%6$d, realPrice:%7$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, itemId, serviceName, originalPrice, singfanPrice));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/price/delete", method= RequestMethod.POST)
    public void priceDelete(HttpServletRequest request, HttpServletResponse response) {
        StorePriceDeleteResponse result = new StorePriceDeleteResponse();
        StorePriceDeleteRequest storePriceDeleteRequest = request2Bean(request, StorePriceDeleteRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storePriceDeleteRequest.getAccessToken();
        int itemId = storePriceDeleteRequest.getItemId();

        long shopId = getShopId();
        if (shopId > 0){
            ShopHairService shopHairService = shopService.findShopHairService(itemId);
            if (shopHairService != null && shopHairService.getShopId() == shopId){
                shopService.deleteShopHairService(itemId);

                result.setResultCode(ResultCode.SUCCESS);

                traceLog.debug(String.format("ShopClientController.priceDelete() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d", ResultCode.SUCCESS, ip, accessToken, itemId));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.priceDelete() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, itemId));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.priceDelete() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, itemId:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, itemId));
        }

        bean2Response(response, result);
    }

    @RequestMapping(value="/v1/store/order/list", method= RequestMethod.POST)
    public void orderList(HttpServletRequest request, HttpServletResponse response) {
        StoreOrderListResponse result = new StoreOrderListResponse();
        StoreOrderListRequest storeOrderListRequest = request2Bean(request, StoreOrderListRequest.class);

        String ip = getIpAddress(request);
        String accessToken = storeOrderListRequest.getAccessToken();
        int orderStatus = storeOrderListRequest.getOrderStatus();
        int pageIndex = storeOrderListRequest.getPageIndex();
        int pageSize = storeOrderListRequest.getPageSize();

        long shopId = getShopId();
        if (shopId > 0){
            if (orderStatus>=0 && orderStatus<=3 && RequestParamChecker.checkPageIndexAndSize(pageIndex, pageSize)){
                List<Orders> ordersList = orderService.findShopOrderDetailList(shopId, orderStatus, pageIndex, pageSize);
                List<OrderStoreListSummaryPartial> orderStoreListSummaryPartialList = new ArrayList<>();
                for (Orders order : ordersList){
                    OrderStoreListSummaryPartial orderStoreListSummaryPartial = new OrderStoreListSummaryPartial();
                    orderStoreListSummaryPartial.setOrderImgUrl(order.getOrderIcon());
                    orderStoreListSummaryPartial.setOrderName(order.getOrderName());
                    orderStoreListSummaryPartial.setOrderCommentLevel(order.getCommentStar());
                    orderStoreListSummaryPartial.setBarberId(order.getBarberId());
                    orderStoreListSummaryPartial.setBarberName(order.getBarberName());
                    orderStoreListSummaryPartial.setCustomerPhoneNum(order.getCustomerPhoneNumber());
                    orderStoreListSummaryPartial.setOrderOriginalPrice(order.getOriginalPrice());
                    orderStoreListSummaryPartial.setOrderPrice(order.getPrice());
                    orderStoreListSummaryPartial.setOrderStatus(order.getStatus());
                    orderStoreListSummaryPartial.setOrderCreateTime(order.getCreateTime().getTime());
                    orderStoreListSummaryPartial.setOrderAppointmentDay(String.valueOf(order.getAppointmentDay()));
                    orderStoreListSummaryPartial.setOrderAppointmentClock(order.getAppointmentClock());
                    orderStoreListSummaryPartial.setOrderID(order.getId());

                    orderStoreListSummaryPartialList.add(orderStoreListSummaryPartial);
                }

                result.setResultCode(ResultCode.SUCCESS);
                result.setStoreOrderPartialList(orderStoreListSummaryPartialList);

                traceLog.debug(String.format("ShopClientController.priceDelete() successful -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderStatus:%4$d", ResultCode.SUCCESS, ip, accessToken, orderStatus));
            }
            else {
                result.setResultCode(ResultCode.REQUEST_PARAM_ERROR);
                traceLog.error(String.format("ShopClientController.priceDelete() error with REQUEST_PARAM_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderStatus:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, orderStatus));
            }
        }
        else {
            result.setResultCode(ResultCode.ACCESS_TOKEN_ERROR);
            traceLog.error(String.format("ShopClientController.priceDelete() error with ACCESS_TOKEN_ERROR -> resultCode:%1$d, ip:%2$s, accessToken:%3$s, orderStatus:%4$d", ResultCode.ACCESS_TOKEN_ERROR, ip, accessToken, orderStatus));
        }

        bean2Response(response, result);
    }

    @Override
    protected void bean2Response(HttpServletResponse response, ResponseModelBase responseModel){
        try {
            CustomerTokenHolder.unbindCustomerToken();
            BarberTokenHolder.unbindBarberToken();
            ShopTokenHolder.unbindShopToken();

            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            String responseText = JsonUtil.bean2Json(responseModel);
            response.getWriter().write(responseText);
        }
        catch (IOException e) {
            traceLog.error(String.format("%1$s.bean2Response() error -> %2$s", this.getClass().getSimpleName(), e.getMessage()));
            e.printStackTrace();
        }
    }

    private long getShopId() {
        long shopId = 0;

        if (ShopTokenHolder.getCurrentShopToken() != null){
            shopId = ShopTokenHolder.getCurrentShopToken().getShopId();
        }

        return shopId;
    }
}